//init.js
var error = document.getElementById('error');
var musicArray =[];
function initMusic(){
    for(var i=0;i<1;i++){
        var music = document.getElementById('music0'+(i+1));
        musicArray.push(music);
        music.load();
    }
}


function ImgLoadingByFile(imgArray,loadPageID,loadTxtID,readyID,musicID,showpageID){
    if(sessionStorage.getItem("pageloaded")){
        $('#'+loadTxtID).html('100%');
        $('#'+loadTxtID).hide();
        $('#'+readyID).show();
        $('#'+loadPageID).one('click',function(){
            var timer = setTimeout(function(){
                $('.scaleOut').addClass('load-hide');
                $('#'+loadPageID).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                    $('#'+loadPageID).hide();
                    $('#'+showpageID).show();
                    Carousel.init();
                });

                initMusic();
                var player = document.getElementById(musicID);
                player.load();
                error.load();
                player.play();
                clearTimeout(timer);
            },500);
        });
    }else{
        var imgLoad = 0;
        if(imgArray.length>0){
            var imgTotal = imgArray.length;
            var percent = 0;
            var img = [];
            for(var i = 0;i<imgArray.length;i++){
                img[i] = new Image();
                img[i].src=imgArray[i];
                img[i].onload = function(){
                    imgLoad++;
                    percent = parseInt(imgLoad/imgTotal*100);
                    $('#'+loadTxtID).html(percent+'%');
                    if(percent>=100){
                      $('#'+loadTxtID).hide();
                        $('#'+readyID).show();
                        $('#'+loadPageID).one('click',function(){
                            var timer = setTimeout(function(){
                                initMusic();
                                var player = document.getElementById(musicID);
                                player.play();
                                error.load();
                                if(player.paused){
                                    player.play();
                                }
                                $('.scaleOut').addClass('load-hide');
                                $('#'+loadPageID).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                                    $('#'+loadPageID).hide();
                                    $('#'+showpageID).show();
                                    Carousel.init();
                                });
                                clearTimeout(timer);
                            },500);
                        });
                        sessionStorage.setItem("pageloaded", "true");
                    }
                }
            }
        }
    }
}


//页面rem
(function (doc, win) {
    var docEl = doc.documentElement,
      resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
      recalc = function () {
        var clientWidth = docEl.clientWidth;
            // var clientWidth = $(".nwrapper").width();
        /*if (!clientWidth) return;*/
        docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
        
      };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

$(document).ready(function(e) {
$("body").css("visibility","visible");$("body").addClass("jbox");

$("input").focus(function(){
    $('#page-landscape').hide();
    $('#page-portrait').show();
});



});




setTimeout(function () {$("body").css("visibility","visible");$("body").addClass("jbox");}, 200);

//横屏 
function landscape(){
    //var w = window.innerWidth;
    //var h = window.innerHeight;
    var w = window.Utils.windowW();
    var h = window.Utils.windowH();
    $("body").css({"width":w,"height":h});
    $('#page-landscape').css({"width":w,"height":h});
    //$('#page-portrait').css({"width":w,"height":h});


    $('#page-landscape').show();
    $('#page-portrait').hide();
}
var firstInit = true;

//竖屏 750 1190
function portrait02(){
    var w = window.Utils.windowW();
    var h = window.Utils.windowH();
    $("body").css({"width":w,"height":h});
    $('#page-portrait').css({"width":w,"height":h});
    $('#pageContainer').css({"width":w,"height":h});
    //$('.load-page').css({"width":w,"height":h});
    $('#page-landscape').hide();
    $('#page-portrait').show();
    $('.start').css({'left':113/750*w+'px','top':1068/1206*h+'px'});
    //初始化加载
    if(firstInit){
        var imgFile = [
            './img/draw_bj.png',
            './img/draw_btl.png',
            './img/draw_btr.png',
            './img/fangjian_1.png',
            './img/fangjian_2.png',
            './img/fangjian_3.png',
            './img/fangjian_4.png',
            './img/fangjian_bj.png',
            './img/fangjian_close.png',
            './img/fanjian_paixu1.png',
            './img/fanjian_paixu1_a.png',
            './img/fanjian_paixu2.png',
            './img/fanjian_paixu2_a.png',
            './img/fanjian_paixu3.png',
            './img/fanjian_paixu3_a.png',
            './img/fanjian_paixu4.png',
            './img/fanjian_paixu4_a.png',
            './img/fanjian_tag1.png',
            './img/fanjian_tag1_a.png',
            './img/fanjian_tag2.png',
            './img/fanjian_tag2_a.png',
            './img/fanjian_tag3.png',
            './img/fanjian_tag3_a.png',
            './img/fanjian_tag4.png',
            './img/fanjian_tag4_a.png',
            './img/fanjian_tag5.png',
            './img/fanjian_tag5_a.png',
            './img/fh.png',
            './img/fh1.png',
            './img/fh2.png',
            './img/fh3.png',
            './img/goods_more_bj.png',
            './img/goods_more_textbj.png',
            './img/goods_more_ww.png',
            './img/index_bj.png',
            './img/index_bt.png',
            './img/index_btbj.png',
            './img/index_dm.png',
            './img/invite1.png',
            './img/invite2.png',
            './img/invite3.png',
            './img/invite4.png',
            './img/invite_bj.png',
            './img/invite_dh.png',
            './img/invite_dh_a.png',
            './img/invite_yq.png',
            './img/jb.png',
            './img/js0.png',
            './img/js1.png',
            './img/js10.png',
            './img/js11.png',
            './img/js12.png',
            './img/js13.png',
            './img/js14.png',
            './img/js15.png',
            './img/js16.png',
            './img/js17.png',
            './img/js18.png',
            './img/js19.png',
            './img/js2.png',
            './img/js20.png',
            './img/js21.png',
            './img/js22.png',
            './img/js23.png',
            './img/js24.png',
            './img/js25.png',
            './img/js26.png',
            './img/js27.png',
            './img/js28.png',
            './img/js29.png',
            './img/js3.png',
            './img/js30.png',
            './img/js4.png',
            './img/js5.png',
            './img/js6.png',
            './img/js7.png',
            './img/js8.png',
            './img/js9.png',
            './img/js_bj.png',
            './img/js_fx.png',
            './img/js_go.png',
            './img/mai_qt1.png',
            './img/mai_qt2.png',
            './img/mai_qt3.png',
            './img/mai_qt4.png',
            './img/mai_qt5.png',
            './img/mai_qt6.png',
            './img/mai_t.png',
            './img/myww_bj.png',
            './img/new_bg.jpg',
			'./img/paihang_bj.png',
            './img/phb_btl.png',
            './img/phb_btl_a.png',
            './img/phb_btr.png',
            './img/phb_btr_a.png',
            './img/phb_f1.png',
            './img/phb_f2.png',
            './img/phb_f3.png',
            './img/phb_jl.png',
            './img/phb_ww.png',
            './img/qd.png',
            './img/qrbt.png',
            './img/recharge1.png',
            './img/recharge2.png',
            './img/recharge3.png',
            './img/recharge4.png',
            './img/recharge5.png',
            './img/recharge_bj.png',
            './img/record_bj.png',
            './img/record_bt1.png',
            './img/record_bt2.png',
            './img/set_bj.png',
            './img/set_bz.png',
            './img/set_lxkf.png',
            './img/set_off.png',
            './img/set_off_a.png',
            './img/set_on.png',
            './img/set_on_a.png',
            './img/set_yx.png',
            './img/set_yy.png',
            './img/shou_l.png',
            './img/shou_r.png',
            './img/text_bj.png',
            './img/text_bj2.png',
            './img/tx.png',
            './img/t_bj.png',
            './img/t_hdxq.png',
            './img/t_szph.png',
            './img/t_zrph.png',
            './img/wdww.png',
            './img/weal_bj.png',
            './img/weal_img.png',
            './img/weal_ok.png',
            './img/weal_on.png',
            './img/xm.png',
            './img/xm_a.png',
            './img/youxi_bt1.png',
            './img/youxi_bt2.png',
            './img/youxi_bt22.png',
            './img/youxi_bt3.png',
            './img/youxi_f1.png',
            './img/youxi_f2.png',
            './img/youxi_f3.png',
            './img/youxi_kuan.png',
            './img/youxi_l.png',
            './img/youxi_l1.png',
            './img/youxi_l2.png',
            './img/youxi_l3.png',
            './img/youxi_l4.png',
            './img/youxi_r.png',
            './img/youxi_r1.png',
            './img/youxi_shou1.png',
            './img/youxi_shou2.png',
            './img/youxi_topbj.png',
            './img/youxi_ww.png',
            './img/yx_bbj.png',
            './img/yx_cbj.png',
            './img/yx_frg.png',
            './img/zhongjiang.png',
            './img/zhongjiang_a.png',
            './img/zhua1.png',
            './img/zhua2.png',
            './img/zhua3.png',
            './img/zhua4.png',
            './img/zhua5.png',
            './img/zhua6.png',
            './img/zhua7.png',
            './img/zhua8.png',
        ];
        ImgLoadingByFile(imgFile,'loadingPage','img-loading-txt','readyGo','musicStar','pageContainer');
        firstInit = false;
    }



    //音乐
    // $(".open").click(function(){
    //     musicStar.pause();
    //     $(this).css("display","none");
    //     $(this).removeClass('show');
    //     $(".clock").css("display","block");
    // });
    // $(".clock").click(function(){
    //     musicStar.play();
    //     $(this).css("display","none");
    //     $(".open").addClass('show');
    //     $(".open").css("display","block");
    // });

}
(function() {
    "use strict";

    function Utils() {
    }

    Utils.isWeiXin = function(){
        return navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/);
    };
    Utils.isQQ = function(){
        return navigator.userAgent.ua.match(/QQ\/([\d\.]+)/);
    };
    Utils.isQZone = function(){
        return navigator.userAgent.ua.indexOf("Qzone/") !== -1;
    };

    Utils.isIos = function() {
        return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
    };
    Utils.isIPhone = function() {
        return navigator.userAgent.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1;
    };
    Utils.isIpad = function() {
        return navigator.userAgent.indexOf('iPad') > -1;
    };
    Utils.isAndroid = function() {
        var u = navigator.userAgent;
        return navigator.userAgent.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
    };
    Utils.isMobile = function() {
        // var u = navigator.userAgent;
        return navigator.userAgent.match(/(iPhone|iPod|Android|ios|SymbianOS)/i) != null;
    };

    // ## 屏幕方向
    Utils.isPortrait = function() {
        if (!Utils.isMobile()) {
            //alert(111);
            return true;

        }
        // 安卓版 微信里面 只用判断 width 和 height
        if (Utils.isAndroid() && Utils.isWeiXin()) {
            if (Utils.windowW() < Utils.windowH()) {
                //alert(22);
                return true;

            } else {
                //alert(331);
                return false;

            }
        }
        var orientation = window['orientation'];
        if (orientation||orientation==0) {
            if (orientation == 90 || orientation == -90) {
                //alert(4442);
                return false;

            }else{
                //alert(555111);
                return true;

            }
        } else {
            if (Utils.windowW() < Utils.windowH()) {
                //alert(666111);
                return true;

            } else {
                //alert(777111);
                return false;

            }
        }
    };
    // ## jquery 获取 window 的宽度
    Utils.windowW = function() {
        // var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
        return $(window).width();
    };
    // ## jquery 获取 window 的高度
    Utils.windowH = function() {
        return $(window).height();
    };
    window.Utils = Utils;
}());
$(function(){
    onResize();
    if (!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
        window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", onResize, false);
    }else{
        window.addEventListener( "resize", onResize, false);
    }
});

function  onResize() {

    if(Utils.isPortrait()){
        if(!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)){

            var timer = setTimeout(function(){
                portrait02();

                clearTimeout(timer);
            },200);
        }else{
            portrait02();
        }
    } else {
        if(!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)){
            var timer = setTimeout(function(){
                landscape();
                clearTimeout(timer);
            },200);
        }else{
            landscape();
        }
    }
}



//接口地址
var URLS = {};
URLS.SERVER_URL = "https://www.easy-mock.com/mock/5a6202ac5d0ce96e08fe2eb8/iope/";
URLS.chance = "chance";//接口名称


//ajax请求公用函数
function ajaxPost(url,data,success,type,error,timeout){
	//设置请求超时时间
	if(!timeout){
		timeout = 10000;
	}
	$.ajax({
		type: type,
		timeout : timeout,
		url: url ,
		data: data ,
		xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
		success: function(data){
			success(data);
		} ,
		error : function(){
			alert("网络请求失败，请稍候再试");
			//error();
		},
		dataType: 'json'
	});
}



//获取url
function GetQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(decodeURIComponent(r[2]));
    }
    return null;
}